/**
 * 2014-4-4 下午10:31:02
 * IndUX
 */
package com.indux.prefset.db.constants;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.indux.prefset.exception.PrefSetException;

/**
 * @author IndUX
 *
 */
public enum ParamName {
	
	// type of setting: sys, user data
	RING_MODE("ring_mode"),
	
	// name of setting, distinct
	RING_VOLUMN("ring_volumn"),
	
	// name of param
	CALL_VOLUMN("call_volumn"),
	
	// value of param
	SYS_VOLUMN("sys_volumn"),
	
	MUSIC_VOLUMN("music_volumn");
	
	private String paramName;
	
	ParamName(String paramName)
	{
		this.paramName = paramName;
	}
	
	public String getParamName()
	{
		return this.paramName;
	}
	
	public static ParamName getBySortIndex(int index) throws PrefSetException
	{
		if (index >= ParamName.values().length)
		{
			throw new PrefSetException();
		}
		
		List<ParamName> list = new ArrayList<ParamName>();
		list.addAll(Arrays.asList(ParamName.values()));
		
		Collections.sort(
		    list, new Comparator<ParamName>() {
			    
			    @Override
			    public int compare(ParamName col1, ParamName col2)
			    {
				    return col1.getParamName().compareToIgnoreCase(
				        col2.getParamName());
			    }
			    
		    });
		
		return list.get(index);
	}
}
